<!--
 * @Description: 原物料追加计划
 * @Author: wangwangwang
 * @Date: 2020-12-01 11:47:46
 * @LastEditors: wangwangwang
 * @LastEditTime: 2020-12-21 17:06:10
-->
<template>
  <div class="flows-content">
    <el-container>
      <el-main style="margin-bottom: 20px; padding: 0;">
        <el-container direction="vertical">
          <FlowHeader :isReadOnly="readOnly" @saveSubmit="handleSubmit(1)" @sendSubmit="handleSubmit(2)" @handleBackEnd="handleSubmit(3)" @handleCC="handleSubmit(4)" @handleAssign="handleSubmit(5)" @handleBackUp="handleSubmit(6)" @handleAssist="handleSubmit(7)" @handleNode="handleSubmit(8)" @handleNodeImage="handleSubmit(9)" @handleCollection="handleSubmit(10)" />
          <el-main class="info">
            <div>
              <el-input v-model="title" class="flow-title" :disabled="readOnly" placeholder="请输入流程标题"></el-input>
            </div>
            <div class="info-top">
              <div class="left">
                <span>单据号码：{{billCode}}</span>
                <span class="text">制单日期：{{billDate}}</span>
              </div>
              <div class="right">
                <span>发起人：{{applyPerson}}</span>
                <span class="text">状态：{{taskTypeText[taskStatus*1]}}</span>
              </div>
            </div>
            <div style="padding-top:20px;">
              <el-form disabled :inline="true" :model="formData" label-width="100px">
                <el-form-item>
                  <span slot="label" style="color:#FF0000;">站点</span>
                  <el-input v-model="formData.station"></el-input>
                </el-form-item>
                <el-form-item prop="materialsId">
                  <span slot="label" style="color:#FF0000;">原物料名称</span>
                  <el-input v-model="formData.materials"></el-input>
                </el-form-item>
                <el-form-item prop="practiceNumer">
                  <span slot="label" style="color:#FF0000;">需求总量</span>
                  <el-input v-model="formData.practiceNumer" type="Number" placeholder="请输入" clearable></el-input>
                </el-form-item>
                <el-form-item prop="needDate">
                  <span slot="label" style="color:#FF0000;">需求日期：</span>
                  <el-date-picker v-model="formData.needDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"></el-date-picker>
                </el-form-item>
              </el-form>
              <div>
                <span class="dialog-title">原物料供应详情</span>
              </div>
              <div style="padding-top:10px">
                <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="formData.list" tooltip-effect="dark">
                  <el-table-column label="合同编号" align="center">
                    <template slot-scope="scope">
                      <span>{{scope.row.contractNo}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="原物料供应商" align="center" prop="supplierName"></el-table-column>
                  <el-table-column label="原物料" align="center">
                    <template slot-scope="scope">
                      <span>{{scope.row.rawMaterialsName}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="规格" align="center" prop="specification"></el-table-column>
                  <el-table-column label="品牌" align="center" prop="brand"></el-table-column>
                  <el-table-column label="份额" align="center" prop="supplierPercent">
                    <template slot-scope="scope">
                      <span v-if='!scope.row.isReadOnly'>/</span>
                      <span v-else>{{scope.row.supplierPercent+'%'}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="是否含运输" align="center">
                    <template slot-scope="scope">
                      <span v-if="scope.row.transportStatus==1" style="color:#00A754;">是</span>
                      <span v-else style="color:#969799;">否</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="供应量" align="center">
                    <template slot-scope="scope">
                      <el-input-number v-model="scope.row.supplierNumber" disabled style="width:100%" :controls="false"></el-input-number>
                    </template>
                  </el-table-column>
                  <el-table-column label="车辆外包合同" align="center" prop="carContractNo">
                    <template slot-scope="scope">
                      <span>{{scope.row.carContractNo}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="车辆供应商" align="center" prop="carCompanyName"></el-table-column>
                </el-table>
              </div>
            </div>
            <div class="flows-details">
              <FlowContent ref="flowcontent" :title='title' :showSendVisible="showSendVisible" @handleCancel="handleCancel" @sendCode="sendCode" @handleFinish="handleFinish" @handleBusiness="handleBusiness" />
            </div>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import FlowContent from '@/components/WorkFlow/flowContent';
import FlowHeader from '@/components/WorkFlow/flowHeader';
import { getUserInfo } from "@/utils/auth.js";
export default {
  components: {
    FlowContent,
    FlowHeader,
  },
  data() {
    return {
      type: 0,
      title: '原物料追加计划',
      billCode: '',
      billDate: '',
      applyPerson: '',
      taskTypeText: ['发起', '已保存', '审批中', '已完成', '撤销', '不通过'],
      taskStatus: 0,
      showSendVisible: false,
      readOnly: false,
      formData: {},
    }
  },
  methods: {
    handleBusiness() {
      const { query } = this.$route;
      const data = JSON.parse(query.dataContent);
      const params = {
        process_success: {
          url: '/icps/system/sign/dataCollection/supplierPlan/saveOrUpdate',
          data: {
            ...data,
          },
          httpMethod: 'post',
        },
        process_failure: ''
      }
      this.showSendVisible = false;
      this.$refs.flowcontent.handleToFlow(params);
    },
    /**
     * @Description: 
     * @Param: 1为保存，2为最后提交/3 中间提交
     * @Author: wangwangwang
     * @param {*} type
     */
    handleFinish() {
    },
    handleSubmit(type) {
      const { query } = this.$route;
      if (query.type * 1 === 2 && type === 2 && query.taskType * 1 !== 2) { // 发起流程
        this.showSendVisible = true;
        return
      }
      const data = {
        dataSource: 'AddOrder',
        dataContent: JSON.stringify({ ...this.formData }), // 业务数据
      }
      this.$refs.flowcontent.saveFlows(type, data);
    },
    handleFlowChat() {
      this.$refs.flowcontent.showFlowNode()
    },
    handleCancel() {
      this.showSendVisible = false;
    },
    /**
     * @Description: 回显业务数据
     * @Param: 
     * @Author: wangwangwang
     */
    initFlowsData(data) {
      data.list = JSON.parse(data.list);
      this.formData = data;
    },
    initFlowsData2() {
      const { query } = this.$route;
      const data = JSON.parse(query.dataContent);
      this.title = query.taskName;
      this.billCode = query.receiptNumber;
      this.billDate = query.createTime;
      this.formData = data;
      this.applyPerson = query.createUserName;
      this.taskStatus = query.taskStatus;
    },
    sendCode(code) {
      this.billCode = code;
    },
  },
  mounted() {
    const { query } = this.$route;
    if (query.type * 1 === 1) { // 发起流程
      this.initFlowsData(query);
      this.$refs.flowcontent.initBaseData('AddOrder');
      this.billDate = new Date().Format('yyyy-MM-dd hh:mm:ss');
      this.applyPerson = getUserInfo().userRealName;
      return
    }
    this.initFlowsData2();
    this.readOnly = true;
  }
}
</script>
<style lang="scss" scoped>
.flows-details {
  margin-top: 20px;
}
.info {
  padding: 0 20px;
  background: #fff;
  .info-top {
    font-size: $font_size;
    color: #000000;
    @include discen_al;
    justify-content: space-between;
    height: 50px;
    border-bottom: 1px #e1e5ed solid;
    .left {
      @include discen_al;
    }
    .text {
      margin-left: 60px;
    }
  }
}
.nav_title {
  @include discen_al;
  align-items: flex-end;
  > div {
    width: 4px;
    height: 24px;
    background: $bg_color;
    margin-right: 10px;
  }
  i {
    margin-left: 5px;
  }
  color: $bg_color;
  font-size: 20px;
  font-weight: bold;
}
</style>
